package com.tsxy.controller.administrator;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.tsxy.common.APIResult;
import com.tsxy.entity.User;
import com.tsxy.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/echarts")
public class EchartsController {
    @Autowired
    private IUserService userService;

    @GetMapping("/user")
    public APIResult getUser(){
        List<User> userList = userService.list();
        int q1 = 0;
        int q2 = 0;
        int q3 = 0;
        int q4 = 0;
        for (User user : userList) {
            Date time = user.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(time);
            switch (quarter){
                case Q1: q1+= 1; break;//第一季度
                case Q2: q2+= 1; break;//第二季度
                case Q3: q3+= 1; break;//第三季度
                case Q4: q4+= 1; break;//第四季度
                default:break;
            }
        }
        return APIResult.success(CollUtil.newArrayList(q1,q2,q3,q4));
    }
}
